package com.xjtu.platform.user.student.firstVisit.impl;

import com.xjtu.platform.common.Utils;
import com.xjtu.platform.common.model.FirstVisit;
import com.xjtu.platform.common.model.User;
import com.xjtu.platform.user.student.firstVisit.FirstVisitService;
import com.xjtu.platform.user.student.firstVisit.SubmitOrderDto;
import com.xjtu.platform.user.student.firstVisit.dao.FirstVisitDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;
import java.util.UUID;

@Service
@Transactional
public class FirstVisitServiceImpl implements FirstVisitService {
    @Resource
    FirstVisitDao dao;
    @Override
    public boolean checkIsInProgress(User user) {
        System.out.println("countttt!!!!!");
        System.out.println(dao.checkIsInProgress(user));
        return dao.checkIsInProgress(user)>0;
    }
    int calculateGrade(SubmitOrderDto dto){
        int score=0;
        score += dto.getValue1();
        score += dto.getValue2();
        score += dto.getValue3();
        score += dto.getValue4();
        score += dto.getValue5();
        score += dto.getValue6();
        score += dto.getValue7();
        score += dto.getValue8();
        score += dto.getValue9();
        score += dto.getValue10();
        return score;
    }
    @Override
    public void insertNewOrder(SubmitOrderDto dto) {
        int grade = calculateGrade(dto);
        System.out.println("grade = "+grade);
        //Float x = Float.parseFloat(dao.getMaxIdPlus1());
        //int x_int = Math.round(x);
        //dto.setVisit_id(String.valueOf(x_int));
        dto.setVisit_id(UUID.randomUUID().toString());
        dto.setType("arrangement");
        dto.setGrade(grade);
        dao.insertNewFirstVisitOrder(dto);
    }

    @Override
    public Map<String, Object> getInfo(FirstVisit dto) {
        return Utils.getPage(dto,()->dao.getInfo(dto));
    }
}
